﻿
using System.Windows.Forms;
using bbtpClient.Entities;

namespace bbtpClient.Controllers
{
    public static class SalesmanController
    {
        public static void ShowCreateOrderForm()
        {
            CreateEditOrderForm form = new CreateEditOrderForm(new Order(), new Client(), new Good());
            form.Show();
        }

        public static void FindClient(string email, CreateEditOrderForm form)
        {
            Client client = ClientController.FindByEmail(email);
            if (client != null)
            {
                form.SetClient(client);
            }
            else
            {
                MessageBox.Show("Клиента с таким адресом электронной почты не существует в база клиентов.");
            }
        }

        public static void CreateOrder(Order order, Client client, CreateEditOrderForm form)
        {
            OrderController.CreateOrder(order, client);
            form.Close();
        }

        public static void ShowGoodsDialog(CreateEditOrderForm form)
        {
            GoodHead[] goods = GoodController.GetAllGoods();
            ChooseGoodForm goodDialog = new ChooseGoodForm(goods);
            if (goodDialog.ShowDialog() == DialogResult.OK)
            {
                Good good = GoodController.GetGood(goodDialog.GoodId);
                form.SetGood(good);
            }
        }

        public static void ShowEditOrderListForm()
        {
            OrderHead[] orders = OrderController.GetAllOrders();
            EditOrderListForm form = new EditOrderListForm(orders);
            form.Show();
        }

        public static void ShowEditOrderForm(long orderId)
        {
            Order order = OrderController.GetOrder(orderId);
            Client client = ClientController.GetClient(order.clientId);
            Good good = GoodController.GetGood(order.goodId);
            CreateEditOrderForm form = new CreateEditOrderForm(order, client, good);
            form.Show();
        }

        public static void CancelOrder(long orderId, EditOrderListForm form)
        {
            OrderController.CancelOrder(orderId);
            form.RemoveSelectedOrder();
        }

        public static void ShowCreateOrderForReturnForm()
        {
            OrderHead[] orders = OrderController.GetSentOrders();
            CreateOrderForReturnForm form = new CreateOrderForReturnForm(orders);
            form.Show();
        }

        public static void CreateOrderForReturn(long orderId, CreateOrderForReturnForm form)
        {
            OrderController.CreateOrderForReturn(orderId);
            form.RemoveSelectedOrder();
        }
    }
}
